/**
 * 
 */
package com.lehecai.core.search.api;

import com.lehecai.core.search.type.SearchEntityKey;

import java.util.Map;

/**
 * 搜索服务配置
 * 需要支持针对不同的服务类型有不同的配置
 * @author Sunshow
 *
 */
public class SearchApiConfig {

    private SearchApiConfigItem defaultConfigItem;

    private Map<SearchEntityKey, SearchApiConfigItem> serviceConfigMap;

    private int defaultTimeout;

    public SearchApiConfigItem getConfig(SearchEntityKey entityKey) {
        if (entityKey == null || this.serviceConfigMap == null || !this.serviceConfigMap.containsKey(entityKey)) {
            return this.getDefaultConfigItem();
        }
        return this.serviceConfigMap.get(entityKey);
    }

    public int getDefaultTimeout() {
        return defaultTimeout;
    }

    public void setDefaultTimeout(int defaultTimeout) {
        this.defaultTimeout = defaultTimeout;
    }

    public void setServiceConfigMap(Map<SearchEntityKey, SearchApiConfigItem> serviceConfigMap) {
        this.serviceConfigMap = serviceConfigMap;
    }

    public SearchApiConfigItem getDefaultConfigItem() {
        return defaultConfigItem;
    }

    public void setDefaultConfigItem(SearchApiConfigItem defaultConfigItem) {
        this.defaultConfigItem = defaultConfigItem;
    }

    public SearchApiConfigItem getConfigItem(SearchEntityKey entityKey) {
        if (entityKey == null || this.serviceConfigMap == null || !this.serviceConfigMap.containsKey(entityKey)) {
            return this.getDefaultConfigItem();
        }
        return this.serviceConfigMap.get(entityKey);
    }
}
